﻿using Autodesk.AutoCAD.Runtime;
using Autodesk.Windows;
using GalaSoft.MvvmLight.Command;
using LeonCad.Core.Ribbons;
using System;
using System.IO;
using Acap = Autodesk.AutoCAD.ApplicationServices.Application;

namespace Demo.Sample {
    class RibbonFromJson {
        private System.Windows.Input.ICommand? _SettingCommand;
        public System.Windows.Input.ICommand SettingCommand {
            get { return _SettingCommand ??= new RelayCommand<object>(ExecuteSettingCommand); }
        }
        private void ExecuteSettingCommand(object? obj) {
            //do something............
            var doc = Acap.DocumentManager.MdiActiveDocument;
            if (obj is RibbonButton button)
                doc.SendStringToExecute("\u001b" + button.CommandParameter?.ToString(), false, true, false);
        }

        private System.Windows.Input.ICommand? _BEnvironmentSet;
        public System.Windows.Input.ICommand BEnvironmentSet {
            get { return _BEnvironmentSet ??= new RelayCommand<object>(ExecuteBEnvironmentSetCommand); }
        }
        private void ExecuteBEnvironmentSetCommand(object? obj) {
            //do something............
            var doc = Acap.DocumentManager.MdiActiveDocument;
            doc.Editor.WriteMessage($"\nhello  ExecuteBEnvironmentSetCommand");
        }
        private static RibbonFromJson? ribbon;
        public static void Do() {
            try {
                ribbon ??= new RibbonFromJson();
                var baseFolder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                RibbonJsonConverte.LoadRibbon(Path.Combine(baseFolder, "ribbonconfig.json"), ribbon);
            }
            catch (System.Exception ex) {
                Acap.ShowAlertDialog(ex.Message);
            }
        }
    }
}
